package org.ktjy.mapper;


import org.ktjy.entity.SysUser;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface SysUserMapper extends JpaRepository<SysUser, Long> {

    SysUser findAllByusrNameAndUsrPassword(String usrName, String usrPassword);
    @Query(nativeQuery = true,value = "select u.*,r.role_name from sys_user u left join sys_role r on u.usr_role_id=r.role_id where u.usr_name=:name and u.usr_password=:pwd")
    SysUser getUserByName(@Param("name") String usrName, @Param("pwd") String usrPassword);
    @Modifying
    @Transactional
    @Query(nativeQuery = true,value = "INSERT INTO `sys_user`( `usr_name`, `usr_password`, `usr_role_id`, `usr_flag`) VALUES (:#{#user.usrName},:#{#user.usrPassword},:#{#user.sysRole.roleId},:#{#user.usrFlag})")
    int getSysUserByAdd(SysUser user);

//    @Query(nativeQuery = true,value = "select * from sys_role  r LEFT JOIN sys_user u ON  r.role_id=u.usr_role_id")
//    List<SysUser> getSysUserBySysRole();
}
